/**
*	插件：必须引入的
*	开发者：雨中磐石
*	地址：www.rockoa.com
*	日期：2023-07-17
*/

js.plugin = {
	scrollbar:function(fun){
		js.importcss('res/perfectscrollbar/perfect-scrollbar.css?rock');
		js.importjs('res/perfectscrollbar/jquery.mousewheel.js?rock');
		js.importjs('res/perfectscrollbar/perfect-scrollbar.js?rock', fun);
		this.scrollbarbo = true;
	}
}



/**
*	插件：浏览器类型处理
*	开发者：雨中磐石
*	地址：www.rockoa.com
*	日期：2023-07-17
*/

js.web = {
	init:function(){
		this.userAgent = navigator.userAgent;
	},
	getagent:function(){
		if(!this.userAgent)this.init();
		return this.userAgent;
	},
	gettypem:function(){
		var llqarr = ["MSIE", "Safari", "Chrome", "iPhone", "Android", "Edge", "QQBrowser", "MicroMessenger","wxwork"];
		var llqobj = {'MicroMessenger':'wxbro'};
		var llqstr = this.getagent().toLowerCase(),strv='unkown';
		for(var i=0;i<llqarr.length;i++){
			if(llqstr.indexOf(llqarr[i].toLowerCase())>-1){
				strv = llqarr[i];
			}
		}
		if(llqobj[strv])strv = llqobj[strv];
		return strv;
	},
	gettype:function(){
		var type = this.gettypem();
		return type;
	},
	ismobile:function(){
		var llqstr = this.getagent().toLowerCase(),bo=false;
		if(llqstr.indexOf('mobile')>-1 || llqstr.indexOf('android')>-1 || llqstr.indexOf('iphone')>-1)bo=true;
		return bo;
	},
	iswxbro:function(){
		var llqstr = this.getagent().toLowerCase(),bo=false;
		if(llqstr.indexOf('micromessenger')>-1)bo=true;
		return bo;
	},
	iswxwork:function(){
		var llqstr = this.getagent().toLowerCase(),bo=false;
		if(llqstr.indexOf('micromessenger')>-1 && llqstr.indexOf('wxwork'))bo=true;
		return bo;
	},
	ismyapp:function(){
		var llqstr = this.getagent().toLowerCase(),bo=false;
		if(llqstr.indexOf('rockdriveapp')>-1)bo=true;
		return bo;
	}
}

/**
*	插件：加载中提示的
*	开发者：雨中磐石
*	地址：www.rockoa.com
*	日期：2023-07-17
*/

js.show = {
	load:function(msg){
		this.showmain('wait', msg, 60);
	},
	showmain:function(lx, txt, sj,fun){
		this.hide();
		var s = '<div id="rockmodelmsg" onclick="$(this).remove()" align="center" style="position:fixed;left:1px;top:30%;z-index:9999;border-radius:10px; background:rgba(0,0,0,0.6);color:white;min-width:80px"><div style="padding:30px;">';
		if(lx=='wait'){
			s+='<div>'+this.ling(40)+'</div>';
			if(txt)s+='<div style="padding-top:5px">'+txt+'</div>';
			if(!sj)sj= 60;
		}
		if(lx=='ok'){
			if(!txt)txt='处理成功';
			s+='<div style="font-size:40px">✔</div>';
			s+='<div>'+txt+'</div>';
		}
		if(lx=='msg' || !lx){
			if(!txt)txt='提示';
			s+='<div style="font-size:40px;color:red">☹</div>';
			s+='<div style="color:red">'+txt+'</div>';
		}
		s+='</div></div>';
		$('body').append(s);
		if(!sj)sj = 3;
		this.rockmodelmsgtime = setTimeout(function(){
			$('#rockmodelmsg').remove();
			if(fun)fun();
		}, sj*1000);
		this.resize();
	},
	resize:function(){
		var le = (winWb()-$('#rockmodelmsg').width())*0.5;
		var te = (winHb()-$('#rockmodelmsg').height())*0.5-10;
		$('#rockmodelmsg').css({'left':''+le+'px','top':''+te+'px'});
	},
	hide:function(){
		clearTimeout(this.rockmodelmsgtime);
		$('#rockmodelmsg').remove();
	},
	success:function(msg){
		this.showmain('ok', msg);
	},
	error:function(msg){
		this.showmain('msg', msg);
	},
	msg:function(cans,fun){
		clearTimeout(this.msgtime);
		var can = {msg:'',time:3,color:'white',type:''};
		if(typeof(cans)=='string')can.msg = cans;
		if(typeof(cans)=='object')for(var i in cans)can[i] = cans[i];
		var sid = 'msgdivstrins';
		var mwx = winWb();
		var str = '<div style="background:rgba(0,0,0,0.5);border-radius:10px;position:fixed;max-width:'+(mwx-20)+'px;color:white;z-index:999;top:20px;left:50%" id="'+sid+'" onclick="$(this).remove()"><div style="padding:10px 20px">';
		str+='<div style="color:'+can.color+'">'+can.msg+'</div>';
		str+='</div></div>';
		$('#'+sid+'').remove()
		$('body').append(str);
		var wei = (mwx-$('#'+sid+'').width())*0.5;
		$('#'+sid+'').css('left',''+wei+'px');
		this.msgtime = setTimeout('$("#'+sid+'").remove()',can.time * 1000);
	},
	ling:function(dx){
		return '<i style="height:'+dx+'px;width:'+dx+'px" class="rock-loading"></i>';
	}
}

js.msg = function(lx, msg, time){
	if(!lx){$('#msgdivstrins').remove();return;}
	var col='';if(!time)time=3;
	if(lx=='msg'){col='red';}
	if(lx=='wait'){col='';time=60}
	this.show.msg({color:col,msg:msg,time:time,type:lx});
}

js.loading = function(str){
	this.show.load(str);
}
js.unloading = function(){
	this.show.hide();
}


/**
*	点击自动取消弹框的
*/
js.bodyclick = {
	add:function(){
		this.addbool = true;
		$('body').click(function(e){js.bodyclick.downbody(this, e);});
	},
	_bodyclick:{},
	downbody:function(o1, e){
		this.allparent = '';
		this.getparenta($(e.target),0);
		var a,s = this.allparent,a1;
		for(a in this._bodyclick){
			a1 = this._bodyclick[a];
			if(s.indexOf(a)<0){
				if(a1.type=='hide'){
					$('#'+a1.objid+'').hide();
				}else{
					$('#'+a1.objid+'').remove();
				}
				if(a1.fun)a1['fun']();
			}
		}
		return true;
	},
	addbody:function(num, type,objid, fun1){
		this._bodyclick[num] = {type:type,objid:objid,fun:fun1};
		if(!this.addbool)this.add();
	},
	getparenta:function(o, oi){
		try{
		if(o[0].nodeName.toUpperCase()=='BODY')return;}catch(e){return;}
		var id = o.attr('id');
		if(!isempt(id)){
			this.allparent+=','+id;
		}
		this.getparenta(o.parent(), oi+1);
	}
}

/**
*	验证中
*/
js.check = {
	email:function(str){
		if(isempt(str) || str.indexOf(' ')>-1)return false;
		if(str.indexOf('.')==-1 || str.indexOf('@')==-1)return false;
		var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
		if(reg.test(str))return false ;
		return true;
	},
	iscnmobile:function(str){
		if(str.length != 11)return false;
		var partten = /^1[3,5,8,4,7,6,9]\d{9}$/;
		if(!partten.test(str)){
			return false;
		}
		return true;
	},
	mobilexing:function(str){
		if(!str)return '';
		return ''+str.substr(0,3)+'****'+str.substr(-4)+'';
	}
}